import axios from 'axios'

const baseURL = 'http://localhost:9090/movie'

export default (url, that, method = 'get', data) => {
  axios.interceptors.request.use((config) => {
    // config.headers[Access-Control-Allow-Origin] = '*'
    that.$toast.loading({
      duration: 0, 
      forbidClick: true,
      message: '加载中...',
    });

    return config
  })
  url = baseURL + url
  return new Promise((resolve, reject) => {
    axios[method](url, data).then((result) => {
      if(result.data.data.data.returnCode === '0') {
        that.$toast.clear();
        // that.$toast.success('加载成功');
      }
      resolve(result.data)
    }).catch((err) => {
      that.$toast.fail('加载失败');
      reject(err)
    });
  })
}
